package jp.ac.aiit.spg.entity;

import java.io.Serializable;
import java.util.*;

import javax.persistence.*;

@Entity
public class SpgProject implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	// version ***********************************
	@Version
	private Integer version;

	public Integer getVersion() {
		return version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}

	// id ***********************************
	@Id
	@GeneratedValue
	private Integer id;

	public Integer getId() {
		return this.id;
	}

	// プロジェクト名 *********************************
	@Column(unique = true, nullable = false)
	private String name;

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	// プロジェクトの説明 *********************************
	@Column(nullable = false)
	private String description;

	public String getDescription() {
		return this.description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	// プロジェクト開始日 ***********************
	@Temporal(TemporalType.DATE)
	private Date startDate;

	public Date getStartDate() {
		return startDate;
	}

	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	// プロジェクト終了日 ***********************
	@Temporal(TemporalType.DATE)
	private Date endDate;

	public Date getEndDate() {
		return endDate;
	}

	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}

	
	
	// プロジェクト・メンバー（複数） ***********************
	@OneToMany(mappedBy = "project", fetch = FetchType.EAGER)
	private Set<SpgMember> members = new HashSet<SpgMember>();

	public Set<SpgMember> getMembers() {
		return this.members;
	}

	public void setMembers(Set<SpgMember> members) {
		this.members = members;
	}

	public void addMember(SpgMember m) {
		// 関連の処理に責任を持つ
		this.members.add(m);
		m.setProject(this);
	}

	public void removeMember(SpgMember m) {
		this.members.remove(m);
	}

	// WBS（１個） *********************************
	@OneToOne
	private SpgWBS wbs;

	public SpgWBS getWbs() {
		return this.wbs;
	}

	public void setWbs(SpgWBS wbs) {
		this.wbs = wbs;
	}


	
}
